home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 45 < prev    next >
Internet Message Format  |  1996-08-06  |  1KB

  1. Path: news.cs.ucla.edu!twinsun!not-for-mail
  2. From: eggert@twinsun.com (Paul Eggert)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Undefined result vs. int's holding undefined values.
  5. Date: 6 Jan 1996 10:45:48 -0800
  6. Organization: Twin Sun Inc, El Segundo, CA, USA
  7. Message-ID: <4cmg0s$1mb@der.twinsun.com>
  8. References: <4ck70b$rd7@news.informix.com> <4ckms5$rd7@news.informix.com>
  9. NNTP-Posting-Host: der.twinsun.com
  10.  
  11. This reminds me of a similar bug I found a long time ago when porting
  12. the Modula-3 runtime, which contained code that acted something like this:
  13.  
  14.     int sum_overflow (int x, int y) {
  15.         return (x + y < x) != (y < 0);
  16.     }
  17.  
  18. The C Standard does not guarantee that the above function works,
  19. since integer overflow leads to undefined behavior,
  20. but when I found that the function did not work with whatever old version
  21. of GCC I was using at the time, I reported it as a bug to the GCC maintainers
  22. and got a fix from them in a few days.
  23.  
  24. Regardless of what the C Standard says, it should be obvious that it's
  25. crucial to have integer overflow checking working properly in an
  26. application that needs it.  If you can't convince SCO that their
  27. implementation's behavior is wrong, then my advice is to switch to a
  28. better supplier.  I've heard that GCC works with SCO....
  29.